/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import entities.Domain;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import util.ISDV12;

/**
 *
 * @author Dragan
 */
public class MultipleRunsV12 {

    static final int POPULATION_SIZE = 20;
    static final int EVOLUTIONS_COUNT = 250;
    static final int TEST_COUNT = 5;
    static final double MAINTENANCE_COST = 1.8E12;
    static final double DERIVATION_COST = 2.2E12;
    static final double RHO = 0.12;

    public static void evolve(Domain domain, String queriesFile) throws Exception {
        String startClause = "MultipleRuns " + new Date();
        String filename = "v12/" + startClause.replace(":", "-") + ".txt";
        String log = startClause + "\n\n";
        String summary = "SUMMARY:\n";

        List<QE_Evolve> evolveTests = new ArrayList<QE_Evolve>();
        for (int i = 1; i <= TEST_COUNT; i++) {
            // evolveTests.add(new QE_Evolve("Test " + queriesFile + "_" + MAINTENANCE_COST + "_" + RHO + "_" + i, domain, EVOLUTIONS_COUNT, POPULATION_SIZE, "v12/" + queriesFile, "v12/domain_" + queriesFile + "_Pop=" + POPULATION_SIZE + "_" + MAINTENANCE_COST + "_" + RHO + "_" + i + ".txt", MAINTENANCE_COST, RHO));
        }
        for (QE_Evolve qe : evolveTests) {
            log += qe.getLog();
            summary += qe.getSummary() + "\n";
        }
        saveText(filename, summary + "\n" + log);
    }

    public static void evolveDerived(Domain domain, String oldDomain, String queriesFile) throws Exception {
        String startClause = "MultipleRuns " + new Date();
        String log = startClause + "\n\n";
        String summary = "SUMMARY:\n";
        String filename = "v12/" + startClause.replace(":", "-") + ".txt";

        List<QE_EvolveDerived> evolveDerivedTests = new ArrayList<QE_EvolveDerived>();


        for (int i = 1; i <= TEST_COUNT; i++) {
            evolveDerivedTests.add(new QE_EvolveDerived("Test " + queriesFile + " derived_" + MAINTENANCE_COST + "_" + RHO + "_" + i, domain, EVOLUTIONS_COUNT, POPULATION_SIZE, "v12/" + queriesFile, oldDomain, "v12/domain_" + queriesFile + MAINTENANCE_COST + "_" + RHO + "_" + i + ".txt", MAINTENANCE_COST, DERIVATION_COST, RHO));
        }
        for (QE_EvolveDerived qed : evolveDerivedTests) {
            log += qed.getLog();
            summary += qed.getSummary() + "\n";
        }
        saveText(filename, summary + "\n" + log);
    }

    public static void main(String[] args) throws Exception {
        Domain domain = new ISDV12().getDomain();
        String oldDomain = "v12/domain100solution/domain_queries100.txt_Pop=20_1.8E12_0.12_3.txt";

        //evolve(domain, "queries0.txt");
        //evolve(domain, "queries0.txt");

        //evolveDerived(domain, oldDomain, "queries75.txt");
        evolveDerived(domain, oldDomain, "queries50.txt");
        //evolveDerived(domain, oldDomain, "queries25.txt");
        //evolveDerived(domain, oldDomain, "queries0.txt");
    }

    public static void saveText(String filename, String text) {
        try {
            PrintStream out = new PrintStream(new FileOutputStream(filename));
            out.print(text);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

